color21 2.2.0
Loading...
Searching...
No Matches
color21.h
Go to the documentation of this file.
1/****************************************************************************
2** Copyright (C) 2020 MikroElektronika d.o.o.
3** Contact: https://www.mikroe.com/contact
4**
5** Permission is hereby granted, free of charge, to any person obtaining a copy
6** of this software and associated documentation files (the "Software"), to deal
7** in the Software without restriction, including without limitation the rights
8** to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9** copies of the Software, and to permit persons to whom the Software is
10** furnished to do so, subject to the following conditions:
11** The above copyright notice and this permission notice shall be
12** included in all copies or substantial portions of the Software.
13**
14** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
16** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
18** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
19** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
20** USE OR OTHER DEALINGS IN THE SOFTWARE.
21****************************************************************************/
22
27
28#ifndef COLOR21_H
29#define COLOR21_H
30
31#ifdef __cplusplus
32extern "C"{
33#endif
34
39#ifdef PREINIT_SUPPORTED
40#include "preinit.h"
41#endif
42
43#ifdef MikroCCoreVersion
44 #if MikroCCoreVersion >= 1
45 #include "delays.h"
46 #endif
47#endif
48
49#include "drv_digital_out.h"
50#include "drv_digital_in.h"
51#include "drv_i2c_master.h"
52
58
63
68
73#define COLOR21_REG_AUXID 0x58
74#define COLOR21_REG_REVID 0x59
75#define COLOR21_REG_ID 0x5A
76#define COLOR21_REG_CFG_12 0x66
77#define COLOR21_REG_ENABLE 0x80
78#define COLOR21_REG_ATIME 0x81
79#define COLOR21_REG_WTIME 0x83
80#define COLOR21_REG_ALS_TH_L_LSB 0x84
81#define COLOR21_REG_ALS_TH_L_MSB 0x85
82#define COLOR21_REG_ALS_TH_H_LSB 0x86
83#define COLOR21_REG_ALS_TH_H_MSB 0x87
84#define COLOR21_REG_STATUS 0x93
85#define COLOR21_REG_ASTATUS 0x94
86#define COLOR21_REG_ADATA_0_L 0x95
87#define COLOR21_REG_ADATA_0_H 0x96
88#define COLOR21_REG_ADATA_1_L 0x97
89#define COLOR21_REG_ADATA_1_H 0x98
90#define COLOR21_REG_ADATA_2_L 0x99
91#define COLOR21_REG_ADATA_2_H 0x9A
92#define COLOR21_REG_ADATA_3_L 0x9B
93#define COLOR21_REG_ADATA_3_H 0x9C
94#define COLOR21_REG_ADATA_4_L 0x9D
95#define COLOR21_REG_ADATA_4_H 0x9E
96#define COLOR21_REG_ADATA_5_L 0x9F
97#define COLOR21_REG_ADATA_5_H 0xA0
98#define COLOR21_REG_ADATA_6_L 0xA1
99#define COLOR21_REG_ADATA_6_H 0xA2
100#define COLOR21_REG_ADATA_7_L 0xA3
101#define COLOR21_REG_ADATA_7_H 0xA4
102#define COLOR21_REG_ADATA_8_L 0xA5
103#define COLOR21_REG_ADATA_8_H 0xA6
104#define COLOR21_REG_ADATA_9_L 0xA7
105#define COLOR21_REG_ADATA_9_H 0xA8
106#define COLOR21_REG_ADATA_10_L 0xA9
107#define COLOR21_REG_ADATA_10_H 0xAA
108#define COLOR21_REG_ADATA_11_L 0xAB
109#define COLOR21_REG_ADATA_11_H 0xAC
110#define COLOR21_REG_ADATA_12_L 0xAD
111#define COLOR21_REG_ADATA_12_H 0xAE
112#define COLOR21_REG_ADATA_13_L 0xAF
113#define COLOR21_REG_ADATA_13_H 0xB0
114#define COLOR21_REG_ADATA_14_L 0xB1
115#define COLOR21_REG_ADATA_14_H 0xB2
116#define COLOR21_REG_ADATA_15_L 0xB3
117#define COLOR21_REG_ADATA_15_H 0xB4
118#define COLOR21_REG_ADATA_16_L 0xB5
119#define COLOR21_REG_ADATA_16_H 0xB6
120#define COLOR21_REG_ADATA_17_L 0xB7
121#define COLOR21_REG_ADATA_17_H 0xB8
122#define COLOR21_REG_STATUS_2 0x90
123#define COLOR21_REG_STATUS_3 0x91
124#define COLOR21_REG_STATUS_5 0xBB
125#define COLOR21_REG_STATUS_4 0xBC
126#define COLOR21_REG_CFG_0 0xBF
127#define COLOR21_REG_CFG_1 0xC6
128#define COLOR21_REG_CFG_3 0xC7
129#define COLOR21_REG_CFG_6 0xF5
130#define COLOR21_REG_CFG_8 0xC9
131#define COLOR21_REG_CFG_9 0xCA
132#define COLOR21_REG_CFG_10 0x65
133#define COLOR21_REG_PERS 0xCF
134#define COLOR21_REG_GPIO 0x6B
135#define COLOR21_REG_ASTEP_LSB 0xD4
136#define COLOR21_REG_ASTEP_MSB 0xD5
137#define COLOR21_REG_CFG_20 0xD6
138#define COLOR21_REG_LED 0xCD
139#define COLOR21_REG_AGC_GAIN_MAX 0xD7
140#define COLOR21_REG_AZ_CONFIG 0xDE
141#define COLOR21_REG_FD_TIME_1 0xE0
142#define COLOR21_REG_FD_TIME_2 0xE2
143#define COLOR21_REG_FD_CFG_0 0xDF
144#define COLOR21_REG_FD_STATUS 0xE3
145#define COLOR21_REG_INTENAB 0xF9
146#define COLOR21_REG_CONTROL 0xFA
147#define COLOR21_REG_FIFO_MAP 0xFC
148#define COLOR21_REG_FIFO_LVL 0xFD
149#define COLOR21_REG_FDATA_L 0xFE
150#define COLOR21_REG_FDATA_H 0xFF
151 // color21_reg
153
158
163
168#define COLOR21_ENABLE_FDEN 0x40
169#define COLOR21_ENABLE_SMUXEN 0x10
170#define COLOR21_ENABLE_WEN 0x08
171#define COLOR21_ENABLE_ALS_EN 0x02
172#define COLOR21_ENABLE_PON 0x01
173#define COLOR21_ENABLE_POFF 0x00
174
179#define COLOR21_CFG_0_LOW_POWER 0x20
180#define COLOR21_CFG_0_REG_BANK 0x10
181#define COLOR21_CFG_0_WLONG 0x04
182
187#define COLOR21_CFG_1_AGAIN_0_5 0x00
188#define COLOR21_CFG_1_AGAIN_1 0x01
189#define COLOR21_CFG_1_AGAIN_2 0x02
190#define COLOR21_CFG_1_AGAIN_4 0x03
191#define COLOR21_CFG_1_AGAIN_8 0x04
192#define COLOR21_CFG_1_AGAIN_16 0x05
193#define COLOR21_CFG_1_AGAIN_32 0x06
194#define COLOR21_CFG_1_AGAIN_64 0x07
195#define COLOR21_CFG_1_AGAIN_128 0x08
196#define COLOR21_CFG_1_AGAIN_256 0x09
197#define COLOR21_CFG_1_AGAIN_512 0x0A
198#define COLOR21_CFG_1_AGAIN_1024 0x0B
199#define COLOR21_CFG_1_AGAIN_2048 0x0C
200#define COLOR21_CFG_1_AGAIN_MASK 0x1F
201
206#define COLOR21_CFG_20_FD_FIFO_8BIT 0x80
207#define COLOR21_CFG_20_AUTO_SMUX_6CH 0x00
208#define COLOR21_CFG_20_AUTO_SMUX_12CH 0x40
209#define COLOR21_CFG_20_AUTO_SMUX_18CH 0x60
210#define COLOR21_CFG_20_AUTO_SMUX_MASK 0x60
211
216#define COLOR21_CONTROL_SW_RESET 0x08
217#define COLOR21_CONTROL_ALS_MAN_AZ 0x04
218#define COLOR21_CONTROL_FIFO_CLR 0x02
219#define COLOR21_CONTROL_CLEAR_SAI_ACT 0x01
220
225#define COLOR21_LED_OFF 0x00
226#define COLOR21_LED_ON 0x80
227#define COLOR21_LED_DRIVE_CURR_MIN 4
228#define COLOR21_LED_DRIVE_CURR_MAX 258
229#define COLOR21_LED_DRIVE_CURR_STEP 2
230#define COLOR21_LED_DRIVE_CURR_DEFAULT 8
231
236#define COLOR21_STATUS_ASAT 0x80
237#define COLOR21_STATUS_AINT 0x08
238#define COLOR21_STATUS_FINT 0x04
239#define COLOR21_STATUS_SINT 0x01
240
245#define COLOR21_ASTATUS_ASAT 0x80
246#define COLOR21_ASTATUS_AGAIN_MASK 0x0F
247
252#define COLOR21_STATUS_2_AVALID 0x40
253#define COLOR21_STATUS_2_ASAT_DIG 0x10
254#define COLOR21_STATUS_2_ASAT_ANA 0x08
255#define COLOR21_STATUS_2_FDSAT_ANA 0x02
256#define COLOR21_STATUS_2_FDSAT_DIG 0x01
257
262#define COLOR21_DEVICE_ID 0x81
263
268#define COLOR21_ACCESS_REG_BANK_ABOVE_80H 0
269#define COLOR21_ACCESS_REG_BANK_20H_7FH 1
270
275#define COLOR21_SINGLE_STEP_MS 0.00278f
276#define COLOR21_ATIME_MAX 255
277#define COLOR21_ASTEP_MAX 65534
278#define COLOR21_INTEGRATION_TIME_MAX ( ( float ) ( COLOR21_ATIME_MAX + 1 ) * ( COLOR21_ASTEP_MAX + 1 ) * COLOR21_SINGLE_STEP_MS )
279#define COLOR21_INTEGRATION_TIME_MIN COLOR21_SINGLE_STEP_MS
280#define COLOR21_INTEGRATION_TIME_DEFAULT 90.0f
281#define COLOR21_WAIT_STEP_MS 2.78f
282#define COLOR21_WTIME_MAX 255
283#define COLOR21_WAIT_TIME_MAX ( ( float ) ( COLOR21_WTIME_MAX + 1 ) * COLOR21_WAIT_STEP_MS )
284#define COLOR21_WAIT_TIME_MIN COLOR21_WAIT_STEP_MS
285#define COLOR21_WAIT_TIME_DEFAULT 100.0f
286
292#define COLOR21_DEVICE_ADDRESS 0x59
293 // color21_set
295
300
305
310#define COLOR21_MAP_MIKROBUS( cfg, mikrobus ) \
311 cfg.scl = MIKROBUS( mikrobus, MIKROBUS_SCL ); \
312 cfg.sda = MIKROBUS( mikrobus, MIKROBUS_SDA ); \
313 cfg.ldr = MIKROBUS( mikrobus, MIKROBUS_RST ); \
314 cfg.io_pin = MIKROBUS( mikrobus, MIKROBUS_PWM ); \
315 cfg.int_pin = MIKROBUS( mikrobus, MIKROBUS_INT )
316 // color21_map // color21
319
324typedef struct
325{
326 uint8_t status;
327 uint8_t astatus;
328 uint16_t ch_fz;
329 uint16_t ch_fy;
330 uint16_t ch_fxl;
331 uint16_t ch_nir;
332 uint16_t ch_2x_vis_1;
333 uint16_t ch_fd_1;
334 uint16_t ch_f2;
335 uint16_t ch_f3;
336 uint16_t ch_f4;
337 uint16_t ch_f6;
338 uint16_t ch_2x_vis_2;
339 uint16_t ch_fd_2;
340 uint16_t ch_f1;
341 uint16_t ch_f5;
342 uint16_t ch_f7;
343 uint16_t ch_f8;
344 uint16_t ch_2x_vis_3;
345 uint16_t ch_fd_3;
346
348
353typedef struct
354{
355 // Output pins
356 digital_out_t ldr;
357
358 // Input pins
359 digital_in_t io_pin;
360 digital_in_t int_pin;
361
362 // Modules
363 i2c_master_t i2c;
364
365 // I2C slave address
367
368} color21_t;
369
374typedef struct
375{
376 pin_name_t scl;
377 pin_name_t sda;
378
379 pin_name_t ldr;
380 pin_name_t io_pin;
381 pin_name_t int_pin;
382
383 uint32_t i2c_speed;
384 uint8_t i2c_address;
385
387
392typedef enum
393{
396
398
404
415
430
444
459err_t color21_generic_write ( color21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len );
460
475err_t color21_generic_read ( color21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len );
476
489err_t color21_write_reg ( color21_t *ctx, uint8_t reg, uint8_t data_in );
490
503err_t color21_read_reg ( color21_t *ctx, uint8_t reg, uint8_t *data_out );
504
518err_t color21_write_reg_word ( color21_t *ctx, uint8_t reg, uint16_t data_in );
519
533err_t color21_read_reg_word ( color21_t *ctx, uint8_t reg, uint16_t *data_out );
534
546
556void color21_set_ldr_pin ( color21_t *ctx, uint8_t state );
557
567
577
590err_t color21_set_reg_bank_access ( color21_t *ctx, uint8_t reg_bank );
591
603
615err_t color21_enable_ext_led ( color21_t *ctx, uint16_t led_curr );
616
630err_t color21_set_integration_time_ms ( color21_t *ctx, float int_time_ms );
631
644err_t color21_set_wait_time_ms ( color21_t *ctx, float wait_time_ms );
645
660
661#ifdef __cplusplus
662}
663#endif
664#endif // COLOR21_H
665 // color21
667
668// ------------------------------------------------------------------------ END
color21_return_value_t
Color 21 Click return value data.
Definition color21.h:393
@ COLOR21_ERROR
Definition color21.h:395
@ COLOR21_OK
Definition color21.h:394
err_t color21_check_communication(color21_t *ctx)
Color 21 check communication function.
err_t color21_init(color21_t *ctx, color21_cfg_t *cfg)
Color 21 initialization function.
err_t color21_default_cfg(color21_t *ctx)
Color 21 default configuration function.
void color21_set_ldr_pin(color21_t *ctx, uint8_t state)
Color 21 set ldr pin function.
err_t color21_read_reg(color21_t *ctx, uint8_t reg, uint8_t *data_out)
Color 21 read register function.
err_t color21_generic_write(color21_t *ctx, uint8_t reg, uint8_t *data_in, uint8_t len)
Color 21 I2C writing function.
err_t color21_set_reg_bank_access(color21_t *ctx, uint8_t reg_bank)
Color 21 set reg bank access function.
err_t color21_set_integration_time_ms(color21_t *ctx, float int_time_ms)
Color 21 set integration time ms function.
err_t color21_enable_ext_led(color21_t *ctx, uint16_t led_curr)
Color 21 enable ext led function.
err_t color21_disable_ext_led(color21_t *ctx)
Color 21 disable ext led function.
void color21_cfg_setup(color21_cfg_t *cfg)
Color 21 configuration object setup function.
uint8_t color21_get_int_pin(color21_t *ctx)
Color 21 get int pin function.
uint8_t color21_get_io_pin(color21_t *ctx)
Color 21 get io pin function.
err_t color21_read_data(color21_t *ctx, color21_data_t *data_out)
Color 21 read data function.
err_t color21_set_wait_time_ms(color21_t *ctx, float wait_time_ms)
Color 21 set wait time ms function.
err_t color21_write_reg_word(color21_t *ctx, uint8_t reg, uint16_t data_in)
Color 21 write register word function.
err_t color21_read_reg_word(color21_t *ctx, uint8_t reg, uint16_t *data_out)
Color 21 read register word function.
err_t color21_write_reg(color21_t *ctx, uint8_t reg, uint8_t data_in)
Color 21 write register function.
err_t color21_generic_read(color21_t *ctx, uint8_t reg, uint8_t *data_out, uint8_t len)
Color 21 I2C reading function.
Color 21 Click configuration object.
Definition color21.h:375
uint32_t i2c_speed
Definition color21.h:383
pin_name_t io_pin
Definition color21.h:380
pin_name_t scl
Definition color21.h:376
pin_name_t ldr
Definition color21.h:379
pin_name_t int_pin
Definition color21.h:381
pin_name_t sda
Definition color21.h:377
uint8_t i2c_address
Definition color21.h:384
Color 21 Click data object.
Definition color21.h:325
uint16_t ch_f4
Definition color21.h:336
uint8_t astatus
Definition color21.h:327
uint16_t ch_fz
Definition color21.h:328
uint16_t ch_2x_vis_3
Definition color21.h:344
uint16_t ch_fd_2
Definition color21.h:339
uint16_t ch_f6
Definition color21.h:337
uint16_t ch_2x_vis_2
Definition color21.h:338
uint16_t ch_fd_1
Definition color21.h:333
uint16_t ch_f2
Definition color21.h:334
uint16_t ch_f3
Definition color21.h:335
uint16_t ch_fxl
Definition color21.h:330
uint16_t ch_fd_3
Definition color21.h:345
uint16_t ch_fy
Definition color21.h:329
uint16_t ch_2x_vis_1
Definition color21.h:332
uint16_t ch_nir
Definition color21.h:331
uint16_t ch_f1
Definition color21.h:340
uint16_t ch_f8
Definition color21.h:343
uint16_t ch_f7
Definition color21.h:342
uint8_t status
Definition color21.h:326
uint16_t ch_f5
Definition color21.h:341
Color 21 Click context object.
Definition color21.h:354
digital_out_t ldr
Definition color21.h:356
digital_in_t int_pin
Definition color21.h:360
i2c_master_t i2c
Definition color21.h:363
uint8_t slave_address
Definition color21.h:366
digital_in_t io_pin
Definition color21.h:359